package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPatrolProperty;
import com.ruoyi.system.service.ITPatrolPropertyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全巡查基本信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-08
 */
@Controller
@RequestMapping("/system/property")
public class TPatrolPropertyController extends BaseController
{
    private String prefix = "system/property";

    @Autowired
    private ITPatrolPropertyService tPatrolPropertyService;

    @GetMapping("/patrol/{id}/{address}")
    public String patrol(@PathVariable("id") String id,@PathVariable("address")String address,ModelMap mmap)
    {
        mmap.put("id",id);
        mmap.put("address",address);
        return prefix + "/property";
    }

    @RequiresPermissions("system:property:view")
    @GetMapping()
    public String property(ModelMap mmap)
    {
        mmap.put("key","landhouse");
        return prefix + "/assets";
    }

    /**
     * 查询安全巡查基本信息列表
     */
    @RequiresPermissions("system:property:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TPatrolProperty tPatrolProperty)
    {
        startPage();
        List<TPatrolProperty> list = tPatrolPropertyService.selectTPatrolPropertyList(tPatrolProperty);
        return getDataTable(list);
    }

    /**
     * 导出安全巡查基本信息列表
     */
    @RequiresPermissions("system:property:export")
    @Log(title = "安全巡查基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPatrolProperty tPatrolProperty)
    {
        List<TPatrolProperty> list = tPatrolPropertyService.selectTPatrolPropertyList(tPatrolProperty);
        ExcelUtil<TPatrolProperty> util = new ExcelUtil<TPatrolProperty>(TPatrolProperty.class);
        return util.exportExcel(list, "安全巡查基本信息数据");
    }

    /**
     * 新增安全巡查基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/addbyId/{assetsId}/{address}")
    public String addbyId(@PathVariable("assetsId") String assetsId,@PathVariable("address") String address,ModelMap mmap)
    {
        mmap.put("assetsId",assetsId);
        mmap.put("address",address);
        return prefix + "/add";
    }

    /**
     * 新增保存安全巡查基本信息
     */
    @RequiresPermissions("system:property:add")
    @Log(title = "安全巡查基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TPatrolProperty tPatrolProperty)
    {
        if (tPatrolProperty.getId() == null){
            tPatrolProperty.setId(generateRandomNumber());
        }
        return toAjax(tPatrolPropertyService.insertTPatrolProperty(tPatrolProperty));
    }

    /**
     * 修改安全巡查基本信息
     */
    @RequiresPermissions("system:property:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TPatrolProperty tPatrolProperty = tPatrolPropertyService.selectTPatrolPropertyById(id);
        mmap.put("tPatrolProperty", tPatrolProperty);
        return prefix + "/edit";
    }

    /**
     * 修改保存安全巡查基本信息
     */
    @RequiresPermissions("system:property:edit")
    @Log(title = "安全巡查基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TPatrolProperty tPatrolProperty)
    {
        return toAjax(tPatrolPropertyService.updateTPatrolProperty(tPatrolProperty));
    }

    /**
     * 删除安全巡查基本信息
     */
    @RequiresPermissions("system:property:remove")
    @Log(title = "安全巡查基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tPatrolPropertyService.deleteTPatrolPropertyByIds(ids));
    }
}
